package com.ruoyi.project.user.cancelaccount.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.user.cancelaccount.domain.CancelAccount;
import com.ruoyi.project.user.cancelaccount.service.ICancelAccountService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 注销用户Controller
 * 
 * @author shixiangwen
 * @date 2022-10-11
 */
@Controller
@RequestMapping("/user/cancelaccount")
public class CancelAccountController extends BaseController
{
    private String prefix = "user/cancelaccount";

    @Autowired
    private ICancelAccountService cancelAccountService;

    @RequiresPermissions("user:cancelaccount:view")
    @GetMapping()
    public String cancelaccount()
    {
        return prefix + "/cancelaccount";
    }

    /**
     * 查询注销用户列表
     */
    @RequiresPermissions("user:cancelaccount:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(CancelAccount cancelAccount)
    {
        startPage();
        List<CancelAccount> list = cancelAccountService.selectCancelAccountList(cancelAccount);
        return getDataTable(list);
    }

    /**
     * 导出注销用户列表
     */
    @RequiresPermissions("user:cancelaccount:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(CancelAccount cancelAccount)
    {
        List<CancelAccount> list = cancelAccountService.selectCancelAccountList(cancelAccount);
        ExcelUtil<CancelAccount> util = new ExcelUtil<CancelAccount>(CancelAccount.class);
        return util.exportExcel(list, "cancelaccount");
    }

    /**
     * 新增注销用户
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存注销用户
     */
    @RequiresPermissions("user:cancelaccount:add")
    @Log(title = "注销用户", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(CancelAccount cancelAccount)
    {
        return toAjax(cancelAccountService.insertCancelAccount(cancelAccount));
    }

    /**
     * 修改注销用户
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        CancelAccount cancelAccount = cancelAccountService.selectCancelAccountById(id);
        mmap.put("cancelAccount", cancelAccount);
        return prefix + "/edit";
    }

    /**
     * 修改保存注销用户
     */
    @RequiresPermissions("user:cancelaccount:edit")
    @Log(title = "注销用户", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(CancelAccount cancelAccount)
    {
        return toAjax(cancelAccountService.updateCancelAccount(cancelAccount));
    }

    /**
     * 删除注销用户
     */
    @RequiresPermissions("user:cancelaccount:remove")
    @Log(title = "注销用户", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(cancelAccountService.deleteCancelAccountByIds(ids));
    }
}
